// Otto by the IdeaLab FabLab
// =====================================================
// SATSUMA (TURTLE) — SHELL ONLY (COEFF-SCALED)
// - 7 side plates with tabs (tab height = material thickness)
// - 1 top plate with slots on 7 sides
// =====================================================


// -------------------- GLOBAL SCALE --------------------
param coeff 3/4


// -------------------- FIT PARAMS --------------------
param materialThickness0 3
param kerf0 0.20
param clearance0 0.15

param materialThickness (materialThickness0 * coeff)
param kerf (kerf0 * coeff)
param clearance (clearance0 * coeff)

// slot width (press-fit)
param slotW (materialThickness + clearance - kerf)


// -------------------- BODY PARAMS (REFERENCE) --------------------
param bodySides 8
param bodyR0 80
param bodyR (bodyR0 * coeff)
param bodyRot 22.5


// -------------------- SHELL PARAMS --------------------
param octSideFactor 0.76536686473
param sidePlateLen (bodyR * octSideFactor)

param shellH0 40
param shellH (shellH0 * coeff)

param shellPlateR0 3
param shellPlateR (shellPlateR0 * coeff)


// -------------------- TAB PARAMS --------------------
param tabSpan0 18
param tabSpan (tabSpan0 * coeff)

// 🔧 TAB HEIGHT = MATERIAL THICKNESS
param tabDepth (materialThickness)

param tabR0 2
param tabR (tabR0 * coeff)


// -------------------- SLOT PLACEMENT --------------------
param apothemFactor 0.92387953251
param apothem (bodyR * apothemFactor)
param slotCenterR (apothem - tabDepth/2)


// -------------------- LAYOUT --------------------
param platesBaseX 0
param platesBaseY (-140 * coeff)
param platesGapY (shellH + 18*coeff)

// X offset for all side plates
param sidePlateOffsetX (180 * coeff)


// =====================================================
// 7 SIDE PLATES (WITH TABS, OFFSET IN X)
// =====================================================

shape roundedRectangle side_plate_blank_0 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 0*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_0 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 0*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_0 {
  add side_plate_blank_0
  add side_plate_tab_0
}


shape roundedRectangle side_plate_blank_1 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 1*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_1 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 1*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_1 {
  add side_plate_blank_1
  add side_plate_tab_1
}


shape roundedRectangle side_plate_blank_2 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 2*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_2 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 2*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_2 {
  add side_plate_blank_2
  add side_plate_tab_2
}


shape roundedRectangle side_plate_blank_3 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 3*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_3 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 3*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_3 {
  add side_plate_blank_3
  add side_plate_tab_3
}


shape roundedRectangle side_plate_blank_4 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 4*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_4 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 4*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_4 {
  add side_plate_blank_4
  add side_plate_tab_4
}


shape roundedRectangle side_plate_blank_5 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 5*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_5 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 5*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_5 {
  add side_plate_blank_5
  add side_plate_tab_5
}


shape roundedRectangle side_plate_blank_6 {
  position: [platesBaseX + sidePlateOffsetX, platesBaseY + 6*platesGapY]
  width: sidePlateLen
  height: shellH
  radius: shellPlateR
  fill: false
}
shape roundedRectangle side_plate_tab_6 {
  position: [
    platesBaseX + sidePlateOffsetX,
    platesBaseY + 6*platesGapY + shellH/2 + tabDepth/2
  ]
  width: tabSpan
  height: tabDepth
  radius: tabR
  fill: false
}
union satsuma_side_plate_6 {
  add side_plate_blank_6
  add side_plate_tab_6
}


// =====================================================
// TOP PLATE WITH 7 SLOTS (NO OFFSET)
// =====================================================

shape polygon satsuma_top_plate_base {
  position: [0, 0]
  sides: bodySides
  radius: bodyR
  rotation: bodyRot
  fill: false
}

shape roundedRectangle top_slot_k0 {
  position: [slotCenterR*0.71710678, slotCenterR*0.70710678]
  width: tabSpan
  height: slotW
  rotation: 135
  fill: false
}

shape roundedRectangle top_slot_k2 {
  position: [-slotCenterR*0.71710678, slotCenterR*0.70710678]
  width: tabSpan
  height: slotW
  rotation: 225
  fill: false
}

shape roundedRectangle top_slot_k3 {
  position: [-slotCenterR - 0.1, 0]
  width: tabSpan
  height: slotW
  rotation: 270
  fill: false
}

shape roundedRectangle top_slot_k4 {
  position: [-slotCenterR*0.71710678, -slotCenterR*0.70710678]
  width: tabSpan
  height: slotW
  rotation: 315
  fill: false
}

shape roundedRectangle top_slot_k5 {
  position: [0, -slotCenterR - 0.1]
  width: tabSpan
  height: slotW
  rotation: 0
  fill: false
}

shape roundedRectangle top_slot_k6 {
  position: [slotCenterR*0.71710678, -slotCenterR*0.70710678]
  width: tabSpan
  height: slotW
  rotation: 45
  fill: false
}

shape roundedRectangle top_slot_k7 {
  position: [slotCenterR + 0.1, 0]
  width: tabSpan
  height: slotW
  rotation: 90
  fill: false
}

difference satsuma_top_plate {
  add satsuma_top_plate_base
  add top_slot_k0
  add top_slot_k2
  add top_slot_k3
  add top_slot_k4
  add top_slot_k5
  add top_slot_k6
  add top_slot_k7
}
